{extend name="public/base" /}

<!--尾部-->

<!--返回顶部-->
{block name="content"}
{__block__}
<input type="hidden" name="mun_url" id="mun_url" value="7,0"/>
<div class="c-r right">

	<div class="label1">
		<div class="title">
			优惠券分类
		</div>
		<div class="information">
			<i></i>
			<p class="h">优惠券</p>
			<p>可设置优惠券，显示用户兑换记录。</p>
			<p>优惠券三种发放方式：积分中心、优惠券码、商家后台发送，只有第一种消耗用户积分，后两者不需要。</p>
			<p>优惠券关闭以后，该批次优惠券用户端不再显示。</p>
			<p></p>
		</div>

		<!--button type="button" class="yh_btn-primary showmodel">
            <span>新增优惠券</span>
        </button-->
		<div class="">

		</div>
		<button class="yh_btn-primary showmodel mtop"><a href="add">新增优惠券</a></button>

		<div class="label-3 label">
			<div class="Tab">
				<table border="0" cellspacing="0" cellpadding="0" style="width: 984px;">
					<tr>
						<th style="width: 35px;"><input type="checkbox" name="" id="" value="" /></th>
						<th style="width: 40px;">ID</th>
						<th style="width: 75px;">剩余数量</th>
						<th style="width: 85px;">优惠券金额</th>
						<th style="width: 85px;">满多少使用</th>
						<th style="width: 140px;">菜单 / 商品</th>
						<th style="width: 90px;">类型</th>
						<th style="width: 115px;">开始时间</th>
						<th style="width: 115px;">结束时间</th>
						<th style="width: 90px;">状态</th>
						<th style="width: 150px;">操作</th>
					</tr>
				</table>
				<table border="0" cellspacing="0" cellpadding="0" style="width: 984px;">
					{foreach name="list" item="data"}
					<tr>
						<td style="width: 35px;"><input type="checkbox" name="" id="" value="" /></td>
						<td style="width: 40px; " class="goodsid" id="goodsid">{$data.disid}</td>
						<td style="width: 75px;">{$data.number}</td>
						<td style="width: 85px;">{$data.money}</td>
						<td style="width: 85px;">{$data.full_money}</td>
						{if condition="$data['type'] == '分类'"}
						<td style="width: 140px;">{$data.commid}</td>
						{elseif condition="$data['type'] == '商品'"/}
						<td style="width: 140px;">{$data.goodsid}</td>
						{else /}
						<td style="width: 140px;"></td>
						{/if}

						<td style="width: 90px;">{$data.type}</td>
						<td style="width: 115px;">{$data.starttime}</td>
						<td style="width: 115px;">{$data.endtime}</td>
						<td style="width: 90px; text-align: center" class="green">
							<b>{$data.types}</b>
						</td>

						{if condition="$data['status'] == '0'"}
						<td style="width: 150px;"><button class="openbtn ml bottom shelves" onclick="shelves($(this),1)">关闭</button><button class="modifybtn open-win ml" onclick="compile('edit?id={$data.disid}')">编辑</button>
							<button class="openbtn" onclick="del('{$data.disid}','__publicPath__/home/coupon/delete')">删除</button></td>


						{elseif condition="$data['status'] == '1'"/}
						<td style="width: 150px;"><button class="modifybtn ml top" onclick="shelves($(this),0)">开启</button><button class="modifybtn open-win ml" onclick="compile('edit?id={$data.disid}')">编辑</button>
							<button class="openbtn" onclick="del('{$data.disid}','__publicPath__/home/coupon/delete')">删除</button></td>

						{/if}


					</tr>
					{/foreach}
				</table>
			</div>
			<div style="text-align: center" class="pages">
				{$list->render()}
			</div>
		</div>

	</div>
</div>

<script src="../../static/home/js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/home/js/js.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/home/js/dateRange.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/home/js/monthPicker.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	function del(id,url){
		if(window.confirm('你确定要删除吗吗？')){
			var data = {
				id:id
			};
			$.ajax({
				type:"get",
				data: data,
				url:url,
				dataType: "json",
				success: function(data){
					if (data == 1) {
						prompt('删除成功',data)
						window.location.reload();
					} else{
						prompt('删除失败',data)
					}
				},
				error:function(){
					prompt('操作失败',0)
				}
			});
		}else{
			//alert("取消");
			return false;
		}


	}
	$("#div_date_demo3 span").css('line-height','1.5')
	var dateRange = new pickerDateRange('date_demo3', {
		aRecent7Days : 'aRecent7DaysDemo3', //最近7天
		isTodayValid : false,
		//startDate : '2013-04-14',
		//endDate : '2013-04-21',
		//needCompare : true,
		//isSingleDay : true,
		//shortOpr : true,
		defaultText : ' 至 ',
		inputTrigger : 'input_trigger_demo3',
		theme : 'ta',
		success : function(obj) {
			$("#dCon_demo3").html('开始时间 : ' + obj.startDate + '<br/>结束时间 : ' + obj.endDate);
			console.log(obj.startDate +'------' +obj.endDate)
		}
	});
	$(function () {
		var leng = $('.Tab tr')
		for (var i = 0; i < leng.length; i++){
			var txt = leng.eq(i).find('.green b').text()
			//alert(txt)
			if(txt == '已开启'){
				leng.eq(i).find('.green b').addClass('putaway')
			}
			if(txt == '已关闭'){
				leng.eq(i).find('.green b').addClass('sold ')
			}
		}

	})
	function shelves(j,v){
		var pid = j.parent().parent().find('.goodsid').text()
		var data = {
			goodsid:pid,status:v,
		};
		$.ajax({
			type:'post',
			url:"__publicPath__/home/coupon/soldOut",			//请求地址加参数
			data: data,
			success: function(data){
				window.location.reload();
				//Parent.find('.green').addClass('red')

			},
			error:function(){
				alert('更新失败')
			}
		});
	}
</script>

{/block}

